package com.ihcy.base.core;

/**
 * 返回实体
 * businessCode 正常 默认 000000
 *
 * @param <T>
 */
public class Result<T> {

    private static final String SUCCEED__CODE = "000000";
    private static final String SUCCEED_MESSAGE = "request is success";


    private String code;

    private String message;

    private T data;

    public Result() {
    }

    public Result(ExceptionEnum exceptionEnum) {
        this.code = exceptionEnum.getCode();
        this.message = exceptionEnum.getMessage();
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    public static <T> Result<T> ok(T object) {
        Result<T> result = new Result<>();
        result.setCode(SUCCEED__CODE);
        result.setMessage(SUCCEED_MESSAGE);
        result.setData(object);
        return result;
    }

    public static Result<Void> fail(String code, String message) {
        Result<Void> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static Result<Void> fail(ExceptionEnum e, String message) {
        Result<Void> result = new Result<>();
        result.setCode(e.getCode());
        result.setMessage(message);
        return result;
    }

    public static Result<Void> fail(ExceptionEnum e) {
        Result<Void> result = new Result<>();
        result.setCode(e.getCode());
        result.setMessage(e.getMessage());
        return result;
    }


}
